﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Revit.MEP.Opening
{
	public partial class ConfigDataXMLSelectForm : System.Windows.Forms.Form
	{
		public ConfigDataXMLSelectForm(bool bConfigData = true)
		{
			this.InitializeComponent();
			this.m_bConfigData = bConfigData;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.FileName = this.txtPathName.Text;
		}

		private void btnSelPath_Click(object sender, EventArgs e)
		{
			if (this.Text == "提资文件路径")
			{
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.InitialDirectory = Product.UserDataLocation;
				saveFileDialog.Filter = "xml files (*.xml)|*.xml";
				saveFileDialog.Title = "选择提资文件保存路径";
				saveFileDialog.RestoreDirectory = true;
				saveFileDialog.FileName = this.FileName.Substring(this.FileName.LastIndexOf('\\') + 1);
				if (saveFileDialog.ShowDialog() == DialogResult.OK)
				{
					this.FileNames.Clear();
					this.FileNames.AddRange(saveFileDialog.FileNames);
					this.UpdateFormCtrlShow();
					return;
				}
			}
			else
			{
				OpenFileDialog openFileDialog = new OpenFileDialog();
				openFileDialog.InitialDirectory = Product.UserDataLocation;
				openFileDialog.Multiselect = !this.m_bConfigData;
				openFileDialog.Title = "请选择文件";
				openFileDialog.Filter = "提资数据文档(*.xml)|*.xml";
				if (openFileDialog.ShowDialog() == DialogResult.OK)
				{
					this.FileNames.Clear();
					this.FileNames.AddRange(openFileDialog.FileNames);
					this.UpdateFormCtrlShow();
				}
			}
		}

		private void ConfigDataXMLSelectForm_Load(object sender, EventArgs e)
		{
			this.Text = (this.m_bConfigData ? "提资文件路径" : "开洞文件路径");
			base.Icon = Resource.YArchitechIcon;
			this.txtPathName.ReadOnly = !this.m_bConfigData;
			this.UpdateFormCtrlShow();
		}

		private void UpdateFormCtrlShow()
		{
			this.txtPathName.Text = this.FileName;
		}

		public string FileName
		{
			get
			{
				return this.FileNames[0];
			}
			set
			{
				this.FileNames.Clear();
				this.FileNames.Add(value);
			}
		}

		public List<string> FileNames
		{
			get
			{
				return this.m_lstFileNames;
			}
		}

		private bool m_bConfigData;

		private List<string> m_lstFileNames = new List<string>();
	}
}
